#include "stdafx.h"
#include "game/gamemgr.h"
#include "input/inputmgr.h"
#include "./program.h"

#define WIN_CAPTION L"BeanWindow"
#define WIN_WIDTH 798
#define WIN_HEIGHT 598

Program::Program()
{

}

Program::~Program()
{

}

void Program::Run(LPTSTR lpstrCmdLine, int nCmdShow)
{
	//wincontainer event
	m_win.OnWinCreate += EventObject<OnWinCreateFunc>(this, &Program::OnWinCreate);
	//m_win.OnWinSize += EventObject<OnWinSizeFunc>(this, &Program::OnWinSize);
	m_win.OnWinClose += EventObject<OnWinCloseFunc>(this, &Program::OnWinClose);
	m_win.OnWinMouseMove += EventObject<OnWinMouseFunc>(this, &Program::OnWinMouseMove);
	m_win.OnWinMouseLButtonDown += EventObject<OnWinMouseFunc>(this, &Program::OnWinMouseLButtonDown);
	m_win.OnWinMouseLButtonUp += EventObject<OnWinMouseFunc>(this, &Program::OnWinMouseLButtonUp);

	GameMgr::GetInstance().OnReady += EventObject<OnGameReadyFunc>(this, &Program::OnGameReady);
	GameMgr::GetInstance().OnExit += EventObject<OnGameExitFunc>(this, &Program::OnGameExit);

	m_win.CreateEx(WIN_CAPTION, WIN_WIDTH, WIN_HEIGHT);
}

void Program::OnWinCreate(Size size)
{
	GameMgr::GetInstance().StartGame(m_win.GetDC());
	GameMgr::GetInstance().SetWinSize(size);
}

void Program::OnWinClose()
{
	GameMgr::GetInstance().StopGame();
}

void Program::OnWinMouseMove(Point pos)
{
	InputMgr::GetInstance().DoMouseMove(pos);
}

void Program::OnWinMouseLButtonDown(Point pos)
{
	InputMgr::GetInstance().DoMouseLButtonDown(pos);
}

void Program::OnWinMouseLButtonUp(Point pos)
{
	InputMgr::GetInstance().DoMouseLButtonUp(pos);
}

void Program::OnGameReady()
{
	m_win.ShowWindow(SW_NORMAL);
}

void Program::OnGameExit()
{
	m_win.CloseWindow();
}